package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.domain.dao.AppModuleDao;
import com.xbongbong.pro.domain.entity.AppModuleEntity;
import com.xbongbong.saas.model.AppModuleModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @description: 模板中心
 * @Author: hongxiao
 * @date: 2019-03-02 19:26
 * @since v1.0
 */
@Service("appModuleModel")
public class AppModuleModelImpl implements AppModuleModel {

    @Resource
    private AppModuleDao appModuleDao;

    @Override
    public Integer insert(AppModuleEntity entity) throws XbbException {
        long now =DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        entity.setDel(DelEnum.NORMAL.getDel());
        return appModuleDao.insert(entity);
    }

    @Override
    public Integer update(AppModuleEntity entity) throws XbbException {
        entity.setUpdateTime((long)DateUtil.getInt());
        return appModuleDao.update(entity);
    }

    @Override
    public List<AppModuleEntity> findEntitys(Map<String, Object> param) {
        return appModuleDao.findEntitys(param);
    }

    @Override
    public void updateBatch(List<AppModuleEntity> appModuleEntityList) {
        appModuleDao.updateBatch(appModuleEntityList);
    }

    @Override
    public void updateName(Long id, String name, String instruction) {
        appModuleDao.updateName(id, name, instruction);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return appModuleDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public AppModuleEntity getByKey(Long key) { return appModuleDao.getByKey(key); }

    @Override
    public AppModuleEntity getByKeyIgnoreDel(Long key) { return appModuleDao.getByKeyIgnoreDel(key); }

    @Override
    public List<AppModuleEntity> getAllList() {
        return appModuleDao.getAllList();
    }

    @Override
    public List<AppModuleEntity> getList(Map<String, Object> param) {
        return findEntitys(param);
    }

    @Override
    public AppModuleEntity getByAlias(String alias) {
        return appModuleDao.getByAlias(alias);
    }

    @Override
    public AppModuleEntity getByMirrorId(Long mirrorId) {
        return appModuleDao.getByMirrorId(mirrorId);
    }

    @Override
    public int save(AppModuleEntity appModuleEntity) throws XbbException {
        if (appModuleEntity.getId() == null || appModuleEntity.getId() == 0) {
            return insert(appModuleEntity);
        }
        return update(appModuleEntity);
    }
}
